/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import control.GuiManager;
import control.SettingsManager;
import java.io.File;
import javax.swing.JFileChooser;

/**
 *
 * @author Jojo
 */
public class LejosOptionsDialog extends javax.swing.JDialog {

    GuiManager guiMan;
    final JFileChooser fc;
    
    
    java.util.ResourceBundle langBundle = GuiManager.getLangBundle();
    /**
     * Creates new form LejosOptionsDialog
     */
    public LejosOptionsDialog(java.awt.Frame parent, boolean modal,GuiManager pGuiMan) {
        super(parent, modal);
        initComponents();
        this.guiMan = pGuiMan;
        fc = new JFileChooser();
        this.setLocationRelativeTo(getParent());
        this.readConfigAndUpdateView();
        //this.guiMan.updateGui();
        this.setVisible(true);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panel_booPath = new javax.swing.JPanel();
        lbl_pathToBoo = new javax.swing.JLabel();
        txtfld_pathToBoo = new javax.swing.JTextField();
        btn_pathToBoo = new javax.swing.JButton();
        filler4 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 10), new java.awt.Dimension(0, 10), new java.awt.Dimension(32767, 10));
        lbl_pathToUploader = new javax.swing.JLabel();
        txtfld_pathToUploader = new javax.swing.JTextField();
        btn_pathToUploader = new javax.swing.JButton();
        filler5 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 10), new java.awt.Dimension(0, 10), new java.awt.Dimension(32767, 10));
        lbl_pathToJar = new javax.swing.JLabel();
        txtfld_pathToJar = new javax.swing.JTextField();
        btn_pathToJar = new javax.swing.JButton();
        filler6 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 10), new java.awt.Dimension(0, 10), new java.awt.Dimension(32767, 10));
        btn_close = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.PAGE_AXIS));

        panel_booPath.setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3));
        panel_booPath.setLayout(new java.awt.GridLayout(12, 1, 20, 5));

        lbl_pathToBoo.setText(langBundle.getString("BooOptionsLblBooPath"));
        panel_booPath.add(lbl_pathToBoo);

        txtfld_pathToBoo.setText("/directory/file");
        txtfld_pathToBoo.setMaximumSize(new java.awt.Dimension(800, 25));
        panel_booPath.add(txtfld_pathToBoo);

        btn_pathToBoo.setText(langBundle.getString("BooOptionsBtnBooPath"));
        btn_pathToBoo.setPreferredSize(new java.awt.Dimension(30, 23));
        btn_pathToBoo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_pathToBooActionPerformed(evt);
            }
        });
        panel_booPath.add(btn_pathToBoo);
        panel_booPath.add(filler4);

        lbl_pathToUploader.setText(langBundle.getString("lejosOptionsLblUploaderPath"));
        panel_booPath.add(lbl_pathToUploader);

        txtfld_pathToUploader.setText("/directory/file");
        txtfld_pathToUploader.setMaximumSize(new java.awt.Dimension(800, 25));
        panel_booPath.add(txtfld_pathToUploader);

        btn_pathToUploader.setText(langBundle.getString("lejosOptionsBtnUploaderBooPath"));
        btn_pathToUploader.setPreferredSize(new java.awt.Dimension(30, 23));
        btn_pathToUploader.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_pathToUploaderActionPerformed(evt);
            }
        });
        panel_booPath.add(btn_pathToUploader);
        panel_booPath.add(filler5);

        lbl_pathToJar.setText(langBundle.getString("lejosOptionsLblJarPath"));
        panel_booPath.add(lbl_pathToJar);

        txtfld_pathToJar.setText("/directory/file");
        txtfld_pathToJar.setMaximumSize(new java.awt.Dimension(800, 25));
        panel_booPath.add(txtfld_pathToJar);

        btn_pathToJar.setText(langBundle.getString("lejosOptionsBtnJarPath"));
        btn_pathToJar.setPreferredSize(new java.awt.Dimension(30, 23));
        btn_pathToJar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_pathToJarActionPerformed(evt);
            }
        });
        panel_booPath.add(btn_pathToJar);
        panel_booPath.add(filler6);

        getContentPane().add(panel_booPath);

        btn_close.setText(langBundle.getString("BooEditorOptionsBtnClose"));
        btn_close.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_closeActionPerformed(evt);
            }
        });
        getContentPane().add(btn_close);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btn_pathToBooActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_pathToBooActionPerformed

        int returnVal = fc.showOpenDialog(this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            this.txtfld_pathToBoo.setText(file.getAbsolutePath());
        }
    }//GEN-LAST:event_btn_pathToBooActionPerformed

    private void btn_pathToUploaderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_pathToUploaderActionPerformed

        int returnVal = fc.showOpenDialog(this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            this.txtfld_pathToUploader.setText(file.getAbsolutePath());
        }
    }//GEN-LAST:event_btn_pathToUploaderActionPerformed

    private void btn_closeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_closeActionPerformed
        saveEditorConfig();
        this.guiMan.updateGui();
        this.dispose();
    }//GEN-LAST:event_btn_closeActionPerformed

    private void btn_pathToJarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_pathToJarActionPerformed
        int returnVal = fc.showOpenDialog(this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            this.txtfld_pathToJar.setText(file.getAbsolutePath());
        }
    }//GEN-LAST:event_btn_pathToJarActionPerformed

    private void readConfigAndUpdateView(){
        this.txtfld_pathToBoo.setText(SettingsManager.getStringSettingValue("PATH_TO_LEJOSCOMPILER"));
        this.txtfld_pathToUploader.setText(SettingsManager.getStringSettingValue("PATH_TO_LEJOSUPLOADER"));
        this.txtfld_pathToJar.setText(SettingsManager.getStringSettingValue("PATH_TO_JAREXTENSION"));
    }
    
    private void saveEditorConfig(){
        SettingsManager.updateSettingsItem("PATH_TO_LEJOSCOMPILER", this.txtfld_pathToBoo.getText());
        SettingsManager.updateSettingsItem("PATH_TO_LEJOSUPLOADER", this.txtfld_pathToUploader.getText());
        SettingsManager.updateSettingsItem("PATH_TO_JAREXTENSION", this.txtfld_pathToJar.getText());
    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_close;
    private javax.swing.JButton btn_pathToBoo;
    private javax.swing.JButton btn_pathToJar;
    private javax.swing.JButton btn_pathToUploader;
    private javax.swing.Box.Filler filler4;
    private javax.swing.Box.Filler filler5;
    private javax.swing.Box.Filler filler6;
    private javax.swing.JLabel lbl_pathToBoo;
    private javax.swing.JLabel lbl_pathToJar;
    private javax.swing.JLabel lbl_pathToUploader;
    private javax.swing.JPanel panel_booPath;
    private javax.swing.JTextField txtfld_pathToBoo;
    private javax.swing.JTextField txtfld_pathToJar;
    private javax.swing.JTextField txtfld_pathToUploader;
    // End of variables declaration//GEN-END:variables
}
